﻿using StructureMap;
using Tarantino.Core;
using Tarantino.Core.Commons.Services.Repositories;
using Tarantino.Core.Commons.Services.Security;
using Tarantino.Samples.Core.Model;

namespace Tarantino.Samples.Core.Services.Security.Impl
{
	[Pluggable(ServiceKeys.Default)]
	public class NewUserService : INewUserService
	{
		private readonly ISystemUserFactory _userFactory;
		private readonly IPersistentObjectRepository _objectRepository;
		private readonly ILoginService _loginService;

		public NewUserService(ISystemUserFactory userFactory, IPersistentObjectRepository objectRepository, ILoginService loginService)
		{
			_userFactory = userFactory;
			_objectRepository = objectRepository;
			_loginService = loginService;
		}

		public string AddNewUser(string emailAddress, string password, string firstName, string lastName, bool rememberMe, ISystemUserRepository repository)
		{
			SystemUser user = _userFactory.CreateUser(emailAddress, password, firstName, lastName);
			_objectRepository.Save(user);
			string feedback = _loginService.Login(emailAddress, password, rememberMe, repository);

			return feedback;
		}
	}
}